package com.rocksdata.mc.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.ctz.commonframe.ui.TitleBarActivity;
import com.ctz.commonframe.ui.widget.AbsAdapter;
import com.ctz.commonframe.ui.widget.AdapterViewHolder;
import com.rocksdata.mc.Constant;
import com.rocksdata.mc.R;
import com.rocksdata.mc.entity.TeacherInfo;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;

import java.util.List;

/**
 * Created by 陈堂正 on 2017/4/27.
 */
@ContentView(R.layout.activity_student_relationship)
public class StudentRelationshipActivity extends TitleBarActivity {
    @ViewInject(R.id.lv_student_relationship)
    private ListView lvStudentRelationship;

    private List<TeacherInfo> teacherList;
    private TeacherListAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitleMiddleText("相关老师");

        teacherList = (List<TeacherInfo>) getIntent().getSerializableExtra("teachers");
        adapter = new TeacherListAdapter(this, teacherList);
        lvStudentRelationship.setAdapter(adapter);
        lvStudentRelationship.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                TeacherInfo bean = adapter.getItem(position);
                Intent intent = new Intent(StudentRelationshipActivity.this, TeacherDetailActivity.class);
                intent.putExtra(Constant.KEY_USER_ID, bean.getStaffCode());
                startActivity(intent);
            }
        });
    }

    private class TeacherListAdapter extends AbsAdapter<TeacherInfo> {
        private Context context;

        public TeacherListAdapter(Context context, List<TeacherInfo> datas) {
            super(context, datas, R.layout.item_teacher_relationship_list_group);
        }

        @Override
        public void convert(AdapterViewHolder holder, TeacherInfo data) {
            ImageView ivFlag = holder.getView(R.id.iv_expanded_flag);
            TextView tvName = holder.getView(R.id.tv_name);
            TextView tvLabel = holder.getView(R.id.tv_teacher_label);
            ivFlag.setVisibility(View.GONE);
            tvName.setText(data.getStaffName());
            tvLabel.setText("");
        }
    }
}
